package club.caihappy.store.service.impl;

import club.caihappy.store.entity.Product;
import club.caihappy.store.mapper.ProductMapper;
import club.caihappy.store.service.IProductService;
import club.caihappy.store.service.ex.ProductNotFoundException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by DELL on 2022/3/22
 **/
@Service
public class ProductServiceImpl implements IProductService {

    @Autowired
    private ProductMapper productMapper;

    @Override
    public List<Product> findHotList() {
        List<Product> products = productMapper.findHotList();
        return products;
    }

    @Override
    public Product getProduct(Integer id) {

        Product product = productMapper.findById(id);
        if (product == null) {
            throw new ProductNotFoundException("商品查询不到");
        }
        return product;
    }
}
